package org.hdax.dm.controller;

import org.hdax.dm.entity.linkuser.LinkUser;
import org.hdax.dm.request.DeleteLinkUserById;
import org.hdax.dm.service.LinkUserService;
import org.hdax.dm.vo.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping
public class LinkUserController {
    @Autowired
    private LinkUserService linkUserService;

    /**
     * 根据用户Id返回当前用户常用购票人列表
     *
     * @param linkUser
     * @return
     */
    @PostMapping(path = "/v/queryLinkUser")
    @ResponseBody
    public CommonResponse<LinkUser> queryLinkUser(@RequestBody LinkUser linkUser) {
        return linkUserService.queryLinkUser(linkUser.getUserId());
    }


    /**
     * 添加常用购票人
     */
    @PostMapping(path = "/v/addLinkUser")
    @ResponseBody
    public CommonResponse<LinkUser> addLinkUser(@RequestBody LinkUser linkUser) {
        return linkUserService.addLinkUser(linkUser);
    }

    /**
     *  验证购票人是否已经存在
     */
    @PostMapping(path = "/v/queryLinkUserByIdCard")
    @ResponseBody
    public CommonResponse queryLinkUserByIdCard(@RequestBody LinkUser linkUser){
        return linkUserService.queryLinkUserByIdCard(linkUser.getIdCard());
    }


    /**
     * 删除联系人
     */
    @PostMapping(path = "/v/deleteLinkUserById")
    public CommonResponse deleteLinkUserById(@RequestBody DeleteLinkUserById deleteLinkUserById){
       return linkUserService.deleteLinkUserById(deleteLinkUserById);
    }

}
